import request from '@/utils/request/req';

// 查询流失客户列表
export function getLossCustomerList(params: { accountCode?: string; wxName?: string; sendWxName?: string; current: number; size: number }) {
  return request({
    url: '/msg/lossCustomer/list',
    method: 'get',
    params
  });
}

// 查询流失提醒激活日志列表
export function getLossCustomerMessagingList(params: { taskName?: string; sendWxIds?: string; wxId?: string; current: number; size: number }) {
  return request({
    url: '/msg/selectLossCustomerMessaging',
    method: 'get',
    params
  });
}

// 激活流失提醒
export function addLossCustomerMessaging(data: {
  taskName: string;
  messageData: string; // JSON格式的消息数据
  sendWxIds?: string;
  wxId: string;
}) {
  return request({
    url: '/msg/addLossCustomerMessaging',
    method: 'post',
    data
  });
}

// 新增流失提醒模板
export function addLossCustomerTemplate(data: {
  account: string;
  templateName: string;
  messageData: string; // JSON格式的消息数据
}) {
  return request({
    url: '/msg/addLossCustomerTemplate',
    method: 'post',
    data
  });
}

// 查询流失提醒模板
export function getLossCustomerTemplateList(params: { account: string; templateName?: string; current: number; size: number }) {
  return request({
    url: '/msg/selectLossCustomerTemplate',
    method: 'get',
    params
  });
}

// 修改流失提醒模板
export function updateLossCustomerTemplate(data: {
  account: string;
  templateId: string;
  templateName: string;
  messageData: string; // JSON格式的消息数据
}) {
  return request({
    url: '/msg/updateLossCustomerTemplate',
    method: 'post',
    data
  });
}

// 删除流失提醒模板
export function deleteLossCustomerTemplate(data: { templateId: string }) {
  return request({
    url: '/msg/deleteLossCustomerTemplate',
    method: 'post',
    data
  });
}

// 类型定义
export interface LossCustomerMessagingRecord {
  taskId: string;
  taskName: string;
  type: string;
  executionTime: string;
  messageData: string;
  sendWxIds: string;
  sendGroupIds: string;
  status: string;
  createBy: string;
  createByStr: string;
  sendWxNames: string[];
  createTime: string;
  isSop: string;
  isDelete: string;
}

export interface LossCustomerTemplateRecord {
  template_id: string;
  account: string;
  message_data: string;
  template_name: string;
}

export interface PageResult<T> {
  records: T[];
  total: string;
  size: number;
  current: number;
}

export interface ApiResponse<T = any> {
  code: number;
  msg: string;
  data: T;
}

// 消息数据类型定义
export interface MessageDataItem {
  type: 'text' | 'image';
  data: string;
}

export type MessageData = MessageDataItem[];
